<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/common/head.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8">
		<title>权限管理</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="${resource }/css/bootstrap.css" />
		<link rel="stylesheet" type="text/css" href="${resource }/css/iconfont.css">
		<script src="${resource }/js/jquery-2.1.1.min.js"></script>
		<script src="${resource }/js/bootstrap.min.js?v=3.4.0"></script>
		<!-- 分页插件，依赖于jquery位于jquery之后 -->
		<script src="${resource }/js/page.js"></script>
	</head>
	<body>
		<div class="row wrapper border-bottom white-bg page-heading">
			<div class="col-sm-4">
				<h2>权限管理</h2>
				<ol class="breadcrumb">
					<li>
						<a href="index.html">主页</a>
					</li>
					<li>
						<strong>权限列表</strong>
					</li>
				</ol>
			</div>
		</div>
		<div class="row wrapper border-bottom white-bg page-heading">
			<div class="col-md-12">
				<!-- 用户列表--bootstrap高级表格使用 -->
				<div class="panel panel-default">
					<div class="panel-heading">
						权限列表
					</div>
					<div class="panel-body">
						<!--table-responsive响应式表格，会自动添加滚动条-->
						<div class="table-responsive">
							<div class="text-center">
								<a data-toggle="modal" class="btncs btn btn-primary" href="form_basic.html#modal-form1" style="float: right;">添加权限</a>
							</div>
							<table class="table">
								<thead>
									<tr>
										<th>编号</th>
										<th>权限名称</th>
										<th>权限描述</th>
										<th>状态</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${list }" var="permission">
									<c:if test="${permission.isStop==1 }">
										<c:set var="isStop" value="可用"></c:set>
									</c:if>
									<c:if test="${permission.isStop==0 }">
										<c:set var="isStop" value="不可用"></c:set>
									</c:if>
										<tr class="odd gradeX">
											<td>${permission.id }</td>
											<td>${permission.permissionName }</td>
											<td>${permission.permissionInfo }</td>
											<td>${isStop }</td>
											<td>
												<a title="修改" data-toggle="modal" class="t-edit" href="form_basic.html#modal-form2" onclick="editflow('${permission.id}','${permission.permissionName }','${permission.permissionInfo }','${permission.isStop}')"><i class="iconfont icon-shuru"></i></a>
	
												
	
											</td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>

						<!--分页显示-->
						<div class="row">
							<div class="col-md-6">
								<div class="pagination" style="margin: 0px;" role="alert" aria-live="polite" aria-relevant="all">显示 1 到 ${permission.getPages()} 页 记录数${permission.getTotal()}</div>
							</div>
							<!-- 动态分页 -->
							<div class="row">
							<div id="page" class="col-md-6" style="text-align: right;float:right;" ></div>
							</div>
						</div>
						<!--分页显示-->
					</div>
				</div>
				<!--表格结束 -->
			</div>
		</div>

		<div id="modal-form1" class="modal fade" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-body">
						<div class="row">
							<div class="col-sm-12 b-r">
								<h3 class="m-t-none m-b">添加权限</h3>
								<form role="form" action="addPermission.do">
									<div class="form-group">
										<label>权限名：</label>
										<input id="Pname" type="text" name="permissionName" placeholder="请输入权限名" class="form-control">
										<label>权限描述：</label>
										<input id="Pinfo" type="text" name="permissionInfo" placeholder="请输入权限描述" class="form-control">
										<label>权限状态：</label>
										<select id="Pstop" class="form-control" name="isStop">
											<option value="1">使用</option>
											<option value="0">停用</option>
										</select>
									</div>
									<div align="center">
										<!--<button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"><strong>保存</strong>
                                    </button>-->
										<input type="submit" onclick="return addok()" />
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id="modal-form2" class="modal fade" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-body">
						<div class="row">
							<div class="col-sm-12 b-r">
								<h3 class="m-t-none m-b">修改权限</h3>
								<form role="form" action="editPermission.do">
									<div class="form-group">
										<label>权限编号：</label>
										<input id="flowid" type="text" name="id"  class="form-control" readonly="readonly">
										<label>权限名：</label>
										<input id="permissionName" name="permissionName" type="text" placeholder="请输入权限名" class="form-control">
										<label>权限描述：</label>
										<input id="permissionInfo" name="permissionInfo" type="text" placeholder="请输入权限描述" class="form-control">
										<label>权限状态：</label>
										<select id="flowName2" class="form-control" name="isStop">
											<option value="1">使用</option>
											<option value="0">停用</option>
										</select>
									</div>
									<div align="center">
										<!--<button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"><strong>登录</strong></button>-->
										<input type="submit" onclick="return editok()"  />
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
			<script>
				function ifdelete(a) {
					var rs = confirm("您确定删除该权限吗？");
					if (rs) {
						  $.ajax({

				                type: "post",

				                url:"delPermission.do",   //控制器路径

				                data: "id="+ a,   //参数

				                cache: false,

				                success: function (msg) {

				                    if (msg == "success") {
										alert("删除成功!");
				                        window.location.href ='showPermission.do';

				                    }

				                    else {

				                        alert("删除失败");

				                    }

				                }

				            });
					}
				}

				function editflow(x, y,z,k) {
					$("#flowid").attr("value", x);
					$("#permissionName").attr("value", y);
					$("#permissionInfo").attr("value", z);
					var options = document.getElementById('flowName2').children;
					if (k==0) {
						options[1].selected=true;
					}else {
						options[0].selected=true;
					}
					
				}

				function addok() {
					var flowName = document.getElementById("Pname").value;
					if(flowName != null && flowName != "") {
						return true;
					} else {
						alert("名称不能为空哦！");
						return false;
					}
				}

				function editok() {
					var flowName = document.getElementById("permissionName").value;
					if(flowName != null && flowName != "") {
						return true;
					} else {
						alert("名称不能为空哦！");
						return false;
					}
				}
			</script>
			<script>
			 $(function(){
					/* 分页插件使用 */
					$("#page").page({/* #page是分页条div的id，调用分页插件page.js中封装的page函数*/
						pageNo:${permission.getPageNo()},/*向page函数传  当前页数，当前页数从controller获取*/
						totalPage:${permission.getPages()},/*向page函数传  总页数，总页数从controller获取*/
						url:"${permission.getUrl()}"/*向page函数传  处理分页的controller地址*/
					});
				}) 
			</script>
	</body>

</html>